<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    		"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html 	xmlns="http://www.w3.org/1999/xhtml"
		xmlns:ui="http://java.sun.com/jsf/facelets"
		xmlns:h="http://java.sun.com/jsf/html"
		xmlns:f="http://java.sun.com/jsf/core"
		xmlns:fn="http://java.sun.com/jsp/jstl/functions"
		xmlns:p="http://primefaces.prime.com.tr/ui">

<h:head>
	<h:title></h:title>
	<style type="text/css" >
		.ui-widget {
		    font-size: 11px !important;
		}
		.ui-selectonemenu {
			top: 5px;
		}
	</style>
	<script type="text/javascript" src="resources/js/jquery.price_format.1.5.js"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			$('.number').priceFormat({prefix: '', centsSeparator: '.', thousandsSeparator: '', limit: 8, centsLimit: 2});
		});
	</script>
</h:head>
	<h:body>
		<h:form id="homeForm" prependId="false">
			<div id="header">
			    <ui:insert name="header">
			    	<ui:include src="/domotic/resources/templates/header.xhtml"/>
			    </ui:insert>
			</div>
			
			<div id="content">
				<p:panel header="Cadastro de Residências" style="min-height: 410px;">
					<p:growl life="3000" showDetail="true" id="messages"></p:growl>
					<h:panelGrid columns="2" id="panelGrid">
						<span>Código: </span>
						<h:panelGroup>
							<p:inputText id="homeIdFake" disabled="true" value="#{homeController.bean.homeId}"></p:inputText>
							<h:inputHidden id="homeId" value="#{homeController.bean.homeId}"></h:inputHidden>
						</h:panelGroup>
						
						<span>Nome: </span>
						<p:inputText id="homeName" maxlength="80" size="60" value="#{homeController.bean.homeName}" required="true" requiredMessage="O Campo 'Nome' é obrigatório"></p:inputText>
						
						<span>Área Total: </span>
						<h:panelGroup>
							<p:inputText id="homeArea" maxlength="10" styleClass="number" value="#{homeController.bean.homeArea}"></p:inputText>
							<span> m²</span>
						</h:panelGroup>
						
						<span>Tipo: </span>
						<p:selectOneMenu id="homeType" style="width: 100px;" value="#{homeController.bean.homeType.homeTypeId}" required="true" requiredMessage="Selecione o tipo de residência.">
							<f:selectItem itemLabel="Select One" itemValue="" />
							<f:selectItems value="#{homeTypeController.all}" var="homeType" itemLabel="#{homeType.homeTypeDescription}" itemValue="#{homeType.homeTypeId}"/>
						</p:selectOneMenu>
					</h:panelGrid>
					<div style="min-height: 6px;" />
					
					<p:commandButton id="saveButton" value="Cadastrar" disabled="#{not empty homeController.bean.homeId and homeController.bean.homeId > 0}" actionListener="#{homeController.insert}" update="messages, homeId, homeIdFake, saveButton, updateButton, deleteButton"></p:commandButton>
					<p:commandButton id="updateButton" value="Alterar" disabled="#{empty homeController.bean.homeId or homeController.bean.homeId eq 0}" onclick="updateConfirmation.show();" type="button"></p:commandButton>
					<p:commandButton id="deleteButton" value="Excluir" disabled="#{empty homeController.bean.homeId or homeController.bean.homeId eq 0}" onclick="deleteConfirmation.show();" type="button"></p:commandButton>
					
					<p:confirmDialog message="Tem certeza que deseja alterar essa residência?" header="Confirmação" severity="alert" modal="true" widgetVar="updateConfirmation">
						<p:commandButton value="Sim" update="messages" oncomplete="updateConfirmation.hide();" actionListener="#{homeController.update}" />
						<p:commandButton value="Não" onclick="updateConfirmation.hide();" type="button" /> 
					</p:confirmDialog>
					<p:confirmDialog message="Tem certeza que deseja excluir essa residência?" header="Confirmação" severity="alert" modal="true" widgetVar="deleteConfirmation">
						<p:commandButton value="Sim" update="messages, homeIdFake, homeId, homeName, homeArea, homeType, saveButton, updateButton, deleteButton" oncomplete="deleteConfirmation.hide();" actionListener="#{homeController.delete}" immediate="true" />
						<p:commandButton value="Não" onclick="deleteConfirmation.hide();" type="button" /> 
					</p:confirmDialog>
					
				</p:panel>
			</div>
			
			<div id="footer">
			  <ui:insert name="footer">
					<ui:include src="/domotic/resources/templates/footer.xhtml"/>
			  </ui:insert>
			</div>
		</h:form>
	</h:body>
</html>